var Tool = require("../../../../utils/ztool.js");
var tool = new Tool();
Page({
  data: {
    inputShowed: false,
    inputVal: "",
    list: [],
    keywords: ''
  },

  callPhone: function (e) {
    if (e.currentTarget.id == "") {
      wx.showToast({
        title: '号码为空',
        icon: 'none',
      });
      return;
    }
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.id //仅为示例，并非真实的电话号码
    });
  },

  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },

  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },

  inputTyping: function (e) {
    this.setData({
      keywords: e.detail.value
    })
  },

  searchgo: function () {
    getData(this)
  },
  //拉入团队
  addpartner: function (e) {
    wx: wx.showModal({
      title: '确定添加?',
      content: '确定将这个司机加入合作团队？',
      showCancel: true,
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          var driverID = e.currentTarget.id
          pulltoTeam(driverID)
        } else {

        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },



  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


})


function getData(that) {
  console.log(that.data.keywords)
  if (that.data.keywords.length <= 0) {
    wx.showToast({
      title: '请输入搜索内容',
    })
    return
  }
  that.data.list = []
  var userInfo = wx.getStorageSync('userInfo')
  wx.showLoading({
    title: '加载中',
  })
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompPatners.ashx',
    data: {
      ID: userInfo.ZID,
      stype: 2,
      pagesize: 200,
      pageindex: 1,
      search: that.data.keywords
    },
    method: 'GET',
    success: function (res) {
      // success

      var data = tool.getRegularJson(res.data);
      console.log(data)
      var code = data.code;
      if (code == 0) {
        that.setData({
          list: that.data.list.concat(data.data),

        })
        console.log(that.data.list)
        wx.hideLoading()
      } else {
        console.log('123')
        console.log(res)
      }
    },
    fail: function (res) {
      console.log(res)
      // fail
    }
  })
}

function pulltoTeam(sijiID) {
  var userInfo = wx.getStorageSync('userInfo')
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompPatners.ashx',
    data: {
      ID: userInfo.ZID,
      sijiid: sijiID,
      stype: 4,
      judge: 1,
    },
    method: 'GET',
    success: function (res) {
      // success
      var code = res.data.code;
      if (code == 0) {
        wx.showToast({
          title: '添加成功',
        })
        wx.navigateBack();
      }
    },
    fail: function () {
      // fail
    }
  })
}